﻿using System;
using System.Data;
using System.Configuration;
using Dcms.Common;
using Dcms.BLL;
using Dcms.Model;
using System.Web;
using WebApp.AppCode;

public partial class Manage_RoleManage_AddRole : System.Web.UI.Page
{
    private int RolID = 0;
    public CompetenceLib CL = new CompetenceLib();
    Dcms_RoleBLL rBll = new Dcms_RoleBLL();
    Dcms_RoleModel rModel = new Dcms_RoleModel();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
           
            CL.IsLogin();

            if (Request["RolID"] != null)
            {
                RolID = Convert.ToInt32(Request["RolID"]);
            }

            if (!IsPostBack)
            {
                if (RolID != 0)
                {
                    rModel = rBll.GetModelByID(RolID);
                    this.txt_RoleName.Text = rModel.Role_Name;
                    this.hid_RoleID.Value = rModel.Role_Id.ToString();
                    this.txt_RoleOrder.Text = rModel.Role_Order.ToString();
                    this.txt_RoleLevel.Text = rModel.Role_level.ToString();
                }
            }
            

        }
        catch (Exception ex)
        {
            Log.LogHandler.LogError("Manage_RoleManage_AddRole.Page_Load", ex);
            throw ex;
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            rModel.Role_Order = Utils.StrToInt(this.txt_RoleOrder.Text,0);
            rModel.Role_Name = this.txt_RoleName.Text;
            rModel.Role_level = Utils.StrToInt(this.txt_RoleLevel.Text,0);
            if (RolID == 0)
            {
                rBll.AddModel(rModel);
                Session.Add("Message", "新角色已添加！");
            }
            else
            {
                rModel.Role_Id = Convert.ToInt32(this.hid_RoleID.Value);
                rBll.Update(rModel);
                Session.Add("Message", "角色名称修改完成！");
            }

            Session.Add("Re", "RoleManage/AddRole.aspx?PermissionID=" + strPermissionID);
            Session.Add("Url", "RoleManage/RoleList.aspx?id=" + strPermissionID);
            Response.Redirect("../Message.aspx",false);
        }
        catch (Exception ex)
        {
            Log.LogHandler.LogError("Manage_RoleManage_AddRole.btnSave_Click", ex);
            throw ex;
        }
    }

    protected string strPermissionID
    {
        get
        {
            return Request.QueryString["PermissionID"] + "";
        }
    }
}
